home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / bc_pas_1.zip / SELFILT.C < prev    next >
C/C++ Source or Header  |  1992-08-31  |  3KB  |  172 lines

  1. /*$Author:   DCODY  $*/
  2. /*$Date:   31 Aug 1992 12:22:28  $*/
  3. /*$Header:   X:/sccs/misc/selfilt.c_v   1.3   31 Aug 1992 12:22:28   DCODY  $*/
  4. /*$Log:   X:/sccs/misc/selfilt.c_v  $
  5.  * 
  6.  *    Rev 1.3   31 Aug 1992 12:22:28   DCODY
  7.  * renamed MVout to MVOut
  8.  * 
  9.  *    Rev 1.2   17 Jul 1992 14:11:28   DCODY
  10.  * always sets the filter now, regardless of board type.
  11.  * 
  12.  *    Rev 1.1   23 Jun 1992 16:33:00   DCODY
  13.  * PAS2 update
  14.  * 
  15.  *    Rev 1.0   15 Jun 1992 09:40:00   BCRANE
  16.  * Initial revision.
  17. */
  18. /*$Logfile:   X:/sccs/misc/selfilt.c_v  $*/
  19. /*$Modtimes$*/
  20.  
  21.     /*\
  22.     |*|----====< SELFILT.C >====----
  23.     |*|
  24.     |*| This module takes a look at the sample rate and requested filter
  25.     |*| setting and comes up with a best match. The
  26.     |*|
  27.     |*| Copyright (c) 1991, Media Vision, Inc. All rights reserved.
  28.     |*|
  29.     \*/
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <malloc.h>
  34.  
  35. #include "pcmio.h"
  36. #include "common.h"
  37.  
  38.   // Pro AudioSpectrum, Rev 1
  39.  
  40.     int FilterTable[] = {
  41.  
  42.         0x00,        /* 000000b     mute - goes to PC speaker    */
  43.         0x24,        /* 111001b     20hz to  2.9khz        */
  44.         0x39,        /* 100100b     20hz to  5.9khz        */
  45.         0x31,        /* 110001b     20hz to  8.9khz        */
  46.         0x29,        /* 101001b     20hz to 11.9khz        */
  47.         0x22,        /* 100010b     20hz to 15.9khz        */
  48.         0x21        /* 100001b     20hz to 17.8khz        */
  49.     };
  50.  
  51.     static int    SetFilter       (int);
  52.     static int    GetSampleMax   (long);
  53.     static int    ValidateFilter (int);
  54.  
  55.  
  56.     /*\
  57.     |*|----====< ChooseInputFilter (long, int) >====----
  58.     |*|
  59.     |*| Choose a good filter setting for PCM input
  60.     |*|
  61.     |*|
  62.     \*/
  63. void ChooseFilter(sr,f)
  64.     long sr;
  65.     int   f;
  66. {
  67. int srmax;
  68.  
  69.     /* if there is a filter override, use it...                         */
  70.  
  71.         if (f != -1) {
  72.             srmax = ValidateFilter(f);
  73.         }
  74.         else {
  75.  
  76.     /* get the maximum filter value for the sample                        */
  77.  
  78.             srmax = GetSampleMax(sr);
  79.         }
  80.  
  81.     /* Set the corrected value now.                                     */
  82.  
  83.         SetFilter(srmax);
  84.  
  85. }
  86.  
  87.  
  88.     /*\
  89.     |*|----====< GetSampleMax() >====----
  90.     |*|
  91.     |*| Return the maximum suggested filter setting for the given sample rate
  92.     |*|
  93.     |*|
  94.     \*/
  95. static int GetSampleMax(sr)
  96.     long sr;
  97. {
  98.  
  99.     /* CD Quality 17897hz                                                */
  100.  
  101.         if ((unsigned long) sr > (unsigned long) 17897L*2)
  102.                 return(6);
  103.  
  104.     /* Cassette Quality 15090hz                                         */
  105.  
  106.         if ((unsigned long) sr > (unsigned long) 15909L*2)
  107.             return(5);
  108.  
  109.     /* FM Radio Quality 11931hz                                         */
  110.  
  111.         if ((unsigned long) sr > (unsigned long) 11931L*2)
  112.             return(4);
  113.  
  114.     /* AM Radio Quality  8948hz                                         */
  115.  
  116.         if ((unsigned long) sr > (unsigned long) 8948L*2)
  117.             return(3);
  118.  
  119.     /* Telphone Quality  5965hz                                         */
  120.  
  121.         if ((unsigned long) sr > (unsigned long) 5965L*2)
  122.             return(2);
  123.  
  124.     /* Male voice quality 2982hz                                        */
  125.  
  126.         return (1);
  127.  
  128. }
  129.  
  130.  
  131.     /*\
  132.     |*|----====< SetFilter() >====----
  133.     |*|
  134.     |*| Output the filter value to the hardware
  135.     |*|
  136.     |*|
  137.     \*/
  138. static int SetFilter(fs)
  139.     int fs;
  140. {
  141.  
  142.     /* get the actual filter data and pass it on...                     */
  143.  
  144.         MVOut (AUDIOFILT, 0x3f, FilterTable[fs]);
  145.  
  146. }
  147.  
  148.  
  149.     /*\
  150.     |*|----====< ValidateFilter(int) >====----
  151.     |*|
  152.     |*| Validate the requested filter level
  153.     |*|
  154.     |*|
  155.     \*/
  156. static int ValidateFilter(f)
  157.    int f;
  158. {
  159.     /* the PROAS100 board has a range of 0 - 6                            */
  160.  
  161.         if ((f < 0) || (f > 6))
  162.             return (6);       /* max it out, it will be trimmed         */
  163.         else
  164.             return (f);       /* let it be...                            */
  165.  
  166. }
  167.  
  168.     /*\
  169.     |*| end of SELFILT.C
  170.     \*/
  171.  
  172.